package com.example.demo.leetcode.top100;

/**
 * ******************************************************
 *
 * @author liugh9
 * @version 1.0
 * @classname _15轮转数组
 * @description
 * @date 2023/06/06 21:34
 * <p>
 * ******************************************************
 */
public class _15轮转数组 {

    public void rotate(int[] nums, int k) {
        int n = nums.length;
        k %= n;

        if (k == 0) {
            return;
        }
        int fast = n - k;

        int[] item = new int[k];
        System.arraycopy(nums, n - k, item, 0, k);
        System.arraycopy(nums, 0, nums, k, fast);
        System.arraycopy(item, 0, nums, 0, k);

    }

}
